import {NTime, FormItemRule, DataTableColumns} from "naive-ui";

export type RowData = {
    name: string
    areaCode: string
    shortName: string
    updateName: string
    createName: string
    parentCode: string
    id: number
    createdAt: Date
    updatedAt: Date
    children?: RowData[]
}

export const columnsInfo: DataTableColumns<RowData> = [
    {
        title: '社区名称',
        ellipsis: {
            tooltip: true
        },
        key: 'name',
    },
    {
        title: '社区代码',
        ellipsis: {
            tooltip: true
        },
        key: 'areaCode',
    },
    {
        title: '社区简称',
        key: 'shortName',
        ellipsis: {
            tooltip: true
        },
    },
    {
        title: '创建时间',
        key: 'createdAt',
        ellipsis: {
            tooltip: true
        },
        render: (row: any) => {
            return h(NTime, {
                time: new Date(row.createdAt)
            })
        }
    },
    {
        title: '创建者',
        key: 'createName',
    },
    {
        title: '最后修改时间',
        key: 'updatedAt',
        ellipsis: {
            tooltip: true
        },
        render: (row: any) => {
            return h(NTime, {
                time: new Date(row.updatedAt)
            })
        }
    },
]

export const formInfo = {
    id: 0,
    areaCode: ``,
    parentCode: ``,
    name: ``,
    shortName: ``,
}

export const rulesInfo = {
    name: {
        required: true,
        validator (rule: FormItemRule, value: string) {
            if (!value) {
                return new Error('社区名称不能为空')
            } else if (value.length > 100) {
                return new Error('社区名称长度不能超过100位')
            }
            return true
        },
    },
    areaCode: {
        required: true,
        message: '社区代码不能为空',
        trigger: 'blur'
    },
}
